package fun.yizhierha.monitor.controller;

import fun.yizhierha.common.annotation.Log;
import fun.yizhierha.common.base.BaseErrDto;
import fun.yizhierha.common.exception.BizCodeEnum;
import fun.yizhierha.common.utils.ValidUtils;
import fun.yizhierha.common.utils.*;


import fun.yizhierha.monitor.domain.vo.RetrieveOnlineUserVo;
import fun.yizhierha.monitor.service.OnlineUserService;
import fun.yizhierha.monitor.service.dto.OnlineUserDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import java.util.Set;

/** generated by EH-Admin
* @author 二哈
* @date Fri Dec 02 10:41:49 CST 2022
**/
@Api(tags = "系统监控：在线用户")
@RestController
@RequestMapping("/api/monitor/onlineuser")
@RequiredArgsConstructor
public class OnlineUserController{

    private final OnlineUserService onlineUserService;

    @ApiOperation("获取在线用户")
    @Log("获取在线用户")
    @GetMapping
    @PreAuthorize("@eh.check('monitor:onlineUser:list')")
    public R<PageUtils<OnlineUserDto>> list(RetrieveOnlineUserVo retrieveOnlineUserVo, Query.PageVo pageVo){
        PageUtils<OnlineUserDto> res = onlineUserService.list(retrieveOnlineUserVo,pageVo);
        return R.<PageUtils<OnlineUserDto>>ok().setData(res);
    }

    @ApiOperation("删除在线用户")
    @Log("删除在线用户")
    @DeleteMapping
    @PreAuthorize("@eh.check('monitor:onlineUser:del')")
    public R delJob(@RequestBody Set<String> usernames){
        onlineUserService.removeIfExist(usernames);
        return R.ok();
    }

    @ApiOperation("导出数据")
    @Log("导出数据")
    @GetMapping("/download")
    @PreAuthorize("@eh.check('monitor:onlineUser:list')")
    public void download(HttpServletResponse response){
        onlineUserService.download(response);
    }

}